from data_type import *


class registers:
    def __init__(self, n):
        self.files = [bit_64() for _ in range(n)]
        self.size = n

    def __getitem__(self, item):
        return self.files[item]

    def __setitem__(self, key, value):
        self.files[key] = value

    def output(self):
        for i in range(self.size):
            print("$%d:\t0x%016x\t%d" % (i, self.files[i].val, self.files[i].val))


class registers_file:
    def __init__(self, n=32):
        self.files = registers(32)

    def ports_out(self, a_addr, b_addr):
        a_out = bit_64(0) if not a_addr else self.files[a_addr]
        b_out = bit_64(0) if not b_addr else self.files[b_addr]
        return a_out.val, b_out.val

    def port_single_out(self, addr):
        return bit_64(0) if not addr else self.files[addr]

    def ports_in(self, addr, c_in):
        if addr:
            self.files[addr] = bit_64(c_in)

    def output(self):
        self.files.output()